package com.itheim.controller;

import com.itheim.anno.Log;
import com.itheim.pojo.Clazz;
import com.itheim.pojo.ClazzQueryParem;
import com.itheim.pojo.PageResult;
import com.itheim.pojo.Result;
import com.itheim.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    //条件分页查询
    @GetMapping
    public Result page(ClazzQueryParem clazzQueryParem){
        log.info("条件分页查询");
        PageResult pageResult= clazzService.page(clazzQueryParem);
        return Result.success(pageResult);
    }
    //添加班级
    @Log
    @PostMapping
    public Result addclazz(@RequestBody Clazz clazz){
        log.info("添加班级");
        clazzService.add(clazz);
        return Result.success();
    }
    //2.4 根据ID查询班级
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据id查询班级");
        Clazz clazz=clazzService.getById(id);
        return Result.success(clazz);
    }

    //2.5 修改班级信息
    @Log
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级信息");
        clazzService.update(clazz);
        return Result.success();
    }
    //2.6 删除班级
    @Log
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级");
        clazzService.deletebyId(id);
        return Result.success();
    }
    //3.6 查询所有班级
    @GetMapping("/list")
    public Result list(){
        log.info("查询所有班级");
        List<Clazz> clazzList=clazzService.list();
        return Result.success(clazzList);
    }
}
